

<template>
  <div class="app-container">
    <div class="filter-container">
      
      <el-select v-model="query.company" v-if="is_system==1" placeholder="选择代理" filterable class="filter-item" style="width:150px;margin-top:6px">
        <el-option label="请选择代理" value="" />
        <el-option
          v-for="item in company"
          :key="item.id"
          :label="item.c_name"
          :value="item.id"
        />
      </el-select>
      <el-date-picker v-model="query.start" style="width:150px;" format="yyyy-MM-dd" type="datetime" placeholder="订单开始日期" />
      <el-date-picker v-model="query.end" style="width:150px" format="yyyy-MM-dd" type="datetime" placeholder="订单结束日期" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-top:8px" @click="handleFilter">查询</el-button>

      <!-- <excelout /> -->
    </div>

    <!-- <el-row style="font-size:14px;color:#666">
        <el-col :span="4">已付金额：{{ counts.paid_money }}</el-col>
    </el-row> -->

    <el-table :key="tableKey" v-loading="listLoading" :data="list" size="mini" border fit highlight-current-row style="width: 100%;margin-top:20px">

      <el-table-column label="结算时间" align="center" >
        <template slot-scope="{row}">
          <span>{{ row.settle_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="代理名称" align="center" >
        <template slot-scope="{row}">
          <span>{{ row.c_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结算金额" align="center" >
        <template slot-scope="{row}">
          <span>{{ row.settle_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" >
        <template slot-scope="{row}">
          <span>{{ row.desc }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px">
        <template slot-scope="{row,$index}">
          <el-button v-if="row.is_paid!=1" type="primary" size="mini" @click="settleDetail(row)">
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="query.page" :limit.sync="query.limit" @pagination="getList" />
      <el-dialog title="列表" :visible.sync="infodetail" width="1000">
      <!-- <span><el-button type="primary" @click="excelout">导出</el-button></span> -->
      <el-table :key="tableKey" v-loading="listLoading2" size="mini" :data="settle_list" border fit highlight-current-row  >

        <el-table-column label="订单日期" align="center" width="150">
          <template slot-scope="{row}">
            <span>{{ row.time_date }}</span>
          </template>
        </el-table-column>
        <el-table-column label="代理名称" align="center" width="180">
          <template slot-scope="{row}">
            <span>{{ row.c_name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户姓名" align="center">
          <template slot-scope="{row}">
            <span>{{ row.real_name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实收金额" align="center" prop="total_money">
          <template slot-scope="{row}">
            <span>{{ row.total_money }}</span>
          </template>
        </el-table-column>
        <el-table-column label="结算金额" align="center" prop="should_settle_money">
          <template slot-scope="{row}">
            <span>{{ row.should_settle_money }}</span>
          </template>
        </el-table-column>

        <el-table-column label="结算状态" align="center">
          <template slot-scope="{row}">
            <span v-if="row.is_settle==1" style="color: #67C23A;">已结算</span>
            <span v-if="row.is_settle==0">未结算</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import {
  getSettleList,getSettleDetailList
} from '@/api/finance'
import excelout from '@/components/excelout/index.vue'

import {
  getCompanyList
} from '@/api/customer'

import waves from '@/directive/waves' // waves directive
import {
  parseTime,getNodes
} from '@/utils'

import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'ComplexTable',
  components: {
    Pagination, excelout
  },
  directives: {
    waves
  },
  filters: {},
  data() {
    return {
      infodetail:false,
      tableKey: 0,
      list: null,
      listLoading2: true,
      listLoading: true,
      query: {
        pay_status: '',
        page: 1,
        city: '',
        limit: 10,
        real_name: '',
        merchant: '',
        b_model: ''
      },
      company: [],
    }
  },
  created() {
    this.nodes = getNodes();
    this.is_system = localStorage.getItem('is_system')
    if(this.is_system==1){
      this.getCompanyList();
    }
    this.cacheQueryFormat()
    this.getList()
    // 添加钩子，页面刷新
    window.addEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  mdestroyed() {
    // 添加钩子，页面刷新
    window.removeEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  methods: {
    
    beforeunloadFn(e) {
      // 刷新页面事件
      sessionStorage.removeItem('finacefirst')
    },
    cacheQueryFormat() {
      const cacheQuery = sessionStorage.getItem('finacefirst')
      if (cacheQuery) {
        this.query = JSON.parse(cacheQuery)
      }
    },
    settleDetail(row){
      this.infodetail = true;
      let pam = {settle_id:row.id}
      getSettleDetailList(pam).then(response => {
        this.settle_list = response.data;
        setTimeout(() => {
          this.listLoading2 = false
        }, 0.2 * 1000)
      })

    },
    handleFilter() {
      this.getList()
    },
    getList() {
      sessionStorage.setItem('finacefirst', JSON.stringify(this.query))
      getSettleList(this.query).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        // this.counts = response.data.list.counts;
        // this.project = response.data.project;
        this.listLoading = false
      })
    },
    getCompanyList() {
      this.listLoading = true
      getCompanyList(this.companylistQuery).then(response => {
        this.company = response.data.data
        //console.log(this.company)
      })
    }
  }
}
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
  }
  select{
    width:100px;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .tb-edit .input-box {
    display: none
  }
  .tb-edit .current-cell .input-box {
    display: block;
    margin-left: -15px;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
    float: left;
  }
</style>
